import unittest


class Solution(object):
    def titleToNumber(self, columnTitle):
        """
        :type columnTitle: str
        :rtype: int
        """
        num = 0
        for char in columnTitle:
            num = num * 26 + (ord(char) - ord('A') + 1)
        return num

class TestTitleToNumber(unittest.TestCase):
    def setUp(self):
        self.solution = Solution()

    def test_single_letters(self):
        self.assertEqual(self.solution.titleToNumber("A"), 1)
        self.assertEqual(self.solution.titleToNumber("B"), 2)
        self.assertEqual(self.solution.titleToNumber("Z"), 26)

    def test_multiple_letters(self):
        self.assertEqual(self.solution.titleToNumber("AA"), 27)
        self.assertEqual(self.solution.titleToNumber("AB"), 28)
        self.assertEqual(self.solution.titleToNumber("AZ"), 52)
        self.assertEqual(self.solution.titleToNumber("BA"), 53)

    def test_longer_cases(self):
        self.assertEqual(self.solution.titleToNumber("ZY"), 701)
        self.assertEqual(self.solution.titleToNumber("BBB"), 703)
        self.assertEqual(self.solution.titleToNumber("FXSHRXW"), 2147483647)

if __name__ == '__main__':
    unittest.main()
